package com.modernyuanshiren;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class Result {
	private int a;
	private int b;

	private static List<Result> availableResults;

	public static List<Result> getAvailableResults(int guessLength) {
		if (availableResults != null) {
			return availableResults;
		}
		availableResults = new ArrayList<>();
		IntStream.range(0, guessLength+1).forEach(a->{
			IntStream.range(0, guessLength-a+1).forEach(b->availableResults.add(new Result(a,b)));
		});
		return availableResults;
	}

	public Result(int a, int b) {
		super();
		this.a = a;
		this.b = b;
	}

	public int getA() {
		return a;
	}

	public int getB() {
		return b;
	}

	public int getRightNumbers() {
		return a + b;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + a;
		result = prime * result + b;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Result other = (Result) obj;
		if (a != other.a)
			return false;
		if (b != other.b)
			return false;
		return true;
	}
}
